﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_GetTeamInfo]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_GetTeamInfo];
GO
CREATE PROCEDURE [dbo].[sproc_GetTeamInfo] 
    @TeamID int

/*

============================================================
功能:    得到@TeamID组的信息
参数:
    @TeamID int        :    组（类）ID

============================================================

*/

AS
BEGIN
SET NOCOUNT ON;

declare @Scale nvarchar(300);
declare @ParentID int;
declare @ParentClassName nvarchar(300);

set @ParentClassName = '';

select
    @ParentID = ClassID, 
    @ParentClassName = ClassName 
From
    uds_class
Where
    classid = (select classparentid from uds_class where classid = @teamid);


set @scale = N'根据已经完成子项目比重结算，计算中';
If exists(select 1 from uds_teaminfo where teamid=@teamid)
begin
    select
        a.classname,
        @ParentID as ParentID,
        @ParentClassName as ParentClassName,
        b.startdate as builddate,
        b.enddate as enddate,
        a.status as status,
        b.scale as ProjectScale,
        a.[classremark] as 'Description',
        @scale as finishedscale 
    from
        uds_class a,
        uds_teaminfo b 
    where
        a.classid = b.teamid
        and b.teamid =@teamid
end
Else
begin
    select
        classname,
        @ParentID as ParentID,
        @ParentClassName as ParentClassName,
        '' as builddate,
        '' as enddate,
        0 as status,
        0 as ProjectScale,
        '' as 'Description',
        @scale as finishedscale,
        0
    from uds_class
    where classid =@TeamID
end

END
GO